import CountUI from '../../components/Count'
import { connect } from 'react-redux'
import {
  createIncrementAction,
  createDecrementAction,
  createIncrementAsyncAction,
} from '../../redux/count_action'

// 映射状态
// const mapStateToProps = state => ({ count: state })
// // 映射操作状态的方法
// const mapDispatchToProps = dispatch => ({
//   jia: data => {
//     // console.log(data)
//     dispatch(createIncrementAction(data))
//   },
//   jian: data => {
//     dispatch(createDecrementAction(data))
//   },
//   jiaAsync: (duration, data) => {
//     dispatch(createIncrementAsyncAction(duration, data))
//   },
// })

export default connect(
  state => ({ count: state }),
  /* dispatch => ({
    jia: data => {
      // console.log(data)
      dispatch(createIncrementAction(data))
    },
    jian: data => {
      dispatch(createDecrementAction(data))
    },
    jiaAsync: (duration, data) => {
      dispatch(createIncrementAsyncAction(duration, data))
    },
  }) */

  // 自动分发
  {
    increment: createIncrementAction,
    decrement: createDecrementAction,
    incrementAsync: createIncrementAsyncAction,
  }
)(CountUI)
